<?php
/**
 * 文件处理类
 * 
 * @version $Id: File.php 176 2011-05-18 03:23:41Z linsir123 $
 */
class lpFile
{
	/**
	 * 写日志文件
	 */
	static function log($file, $content, $mode = 'a+', $size = 10240)
	{
		if ($fp = @fopen($file, $mode)) {
			if ($size > 0 && filesize($file) > $size) {
				@fclose($fp);
				@rename($file, dirname($file).'/'.date('Y-m-d').time().'-'.basename($file));
				$fp = @fopen($file, 'w');
			}
			
			@fwrite($fp, $content);
			@fclose($fp);
		}
	}
	
	/**
	 * 写文件缓存
	 */
	static function cache($file, $array)
	{
		$content = "<?php return ".var_export($array, true).";";
		self::write($file, $content, 'w', 0);
	}
	
	/**
	 * 删除文件
	 */
	static function unlink($file)
	{
		if (is_file($file)) 
			@unlink($file);
	}
}
